package graphics.screens.mode;

import graphics.Background;
import graphics.BootColor;
import graphics.Theme;

import java.util.Timer;
import java.util.TimerTask;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;

import state.State;
import tool.ScreenUtils;
import boot.Boot;

public class OptionScreen extends Canvas implements CommandListener {

	protected static final int Y_MENU_OFFSET = 10;
	protected static final int X_MENU_OFFSET = 5;

	protected final Command cancelCommand = new Command("Cancel", Command.EXIT, 1);

	int index;

	public OptionScreen() {
		addCommand(cancelCommand);
		setCommandListener(this);
	}

	protected void paint(Graphics g) {
		ScreenUtils.setBlackBackground(g);

		Background bg = new Background();
		bg.repaint(g);

		drawMenuEntries(g);
	}

	protected void drawMenuEntries(Graphics g) {

	}

	public void commandAction(Command command, Displayable dis) {
		if (command == cancelCommand) {
			Boot.getInstance().readyToGo();
		}
	}

	protected void drawOnOff(State state, int x, int y, Graphics g) {
		g.setColor(Theme.getMenuColor());
		if (Boot.state().equals(state)) {
			g.drawString(" on", x, y, Graphics.LEFT | Graphics.TOP);
		} else {
			g.drawString(" off", x, y, Graphics.LEFT | Graphics.TOP);
		}
		g.setColor(BootColor.WHITE);
	}

	protected void switchMode(State state) {
		if (Boot.state().equals(state)) {
			Boot.removeState(state);
		} else {
			Boot.addState(state);
		}
	}
	
	protected void delayedReadyToGo() {
		Timer timer = new Timer();
		timer.schedule(new TimerTask() {

			public void run() {				
				Boot.getInstance().readyToGo();
			}
			
		}, 500);
	}
}
